// pages/moneyDetail/index.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    haveMore: false,
    day: '',
    page: 1,
    total_currency: '',
    today_currency: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that=this;
    var obj = {
      unionid: wx.getStorageSync('openid'),
      page: 1
    }
    var sign = app.sort_ASCII(obj)
    wx.request({
      url: app.globalData.new_url + '/redpacket/Withdrawal/balance_detail',
      data: {
        page: 1,
        unionid: wx.getStorageSync('openid'),
        sign:sign
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        that.setData({
          day: res.data.content.list,
        })
        if(res.data.content.count>10){
          that.data.haveMore=true
        }else{
          that.data.haveMore = false
        }
      }
    })
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  // 上拉触底事件，请求记录数据
  onReachBottom: function () {
    const that = this
    let page = that.data.page;
    if (that.data.haveMore) {
      // 请求下一页数据
      page++;
      that.data.page = page
      var obj = {
        unionid: wx.getStorageSync('openid'),
        page: page
      }
      var sign = app.sort_ASCII(obj)
      wx.request({
        url: app.globalData.new_url + '/redpacket/Withdrawal/balance_detail',
        data: {
          page: page,
          unionid: wx.getStorageSync('openid'),
          sign: sign
        },
        method: 'POST',
        header: {
          'Cache-Control': 'max-age=60,public', //60秒
        },
        success: function (res) {
          that.data.day = that.data.day.concat(res.data.content.list);
          that.setData({
            day: that.data.day,
          })
          if (res.data.content.count > 20) {
            that.setData({
              haveMore: true,
            })
          }else{
            that.setData({
              haveMore: false,
            })
          }
        }
      })
    }
  },
})